from Devices.Chiot.BsDevs.ComDev.ComDevParser import ComDevParser
from Devices.Chiot.BsDevs.Stripe.StripeDevice import StripeDevice

class StripeParser(ComDevParser):
    def __ParseCom(stateValue, fullStatus):
        ret, value = StripeParser.GetIntProperty(stateValue, "switch", "on")
        if ret:
            fullStatus.switchStatus = value

        if 1== fullStatus.switchStatus:
            ret, value = StripeParser.GetIntProperty(stateValue, "switch1", "on")
            if ret:
                fullStatus.switch1Status = value
            ret, value = StripeParser.GetIntProperty(stateValue, "switch2", "on")
            if ret:
                fullStatus.switch2Status = value

            ret, value = StripeParser.GetIntProperty(stateValue, "switch3", "on")
            if ret:
                fullStatus.switch3Status = value

            ret, value = StripeParser.GetIntProperty(stateValue, "switch4", "on")
            if ret:
                fullStatus.switch4Status = value

            ret, value = StripeParser.GetIntProperty(stateValue, "switch5", "on")
            if ret:
                fullStatus.switch5Status = value
        else:
            fullStatus.switch1Status = 0
            fullStatus.switch2Status = 0
            fullStatus.switch3Status = 0
            fullStatus.switch4Status = 0
            fullStatus.switch5Status = 0

        ret, value = StripeParser.GetIntProperty(stateValue, "memSwitch", "on")
        if ret:
            fullStatus.memSwitchStatus = value

        ret, value = StripeParser.GetIntProperty(stateValue, "backlight", "on")
        if ret:
            fullStatus.backlightStatus = value
            
        ret, value = StripeParser.GetIntProperty(stateValue, "chargingPro", "on")
        if ret:
            fullStatus.chargingProStatus = value

    def ParseHeartbeat(msgValue, fullStatus):
        if not "stateValue" in msgValue:
            return False
        stateValue = msgValue["stateValue"]

        StripeParser.__ParseCom(stateValue, fullStatus)
        
        StripeParser.GetTimers(stateValue, "timer", fullStatus.timers, StripeDevice.Timer())
        StripeParser.GetDelay(stateValue, "delay", fullStatus.delay)
        return True

    def ParseRptStatus(msgValue, fullStatus):
        if not "stateValue" in msgValue:
            return False
        stateValue = msgValue["stateValue"]

        StripeParser.__ParseCom(stateValue, fullStatus)
        
        return True

    # def ParseFullStatus():
    #     pass
    def ParseHomekitInfo(msgValue, fullStatus):
        parse_ret = 0
        ret, strValue = ComDevParser.GetStrProperty(msgValue, "setupCode")
        if ret:
            fullStatus.setupCode = strValue
            parse_ret += 1

        ret, strValue = ComDevParser.GetStrProperty(msgValue, "setupPayload")
        if ret:
            fullStatus.setupPayload = strValue
            parse_ret += 1

        ret, strValue = ComDevParser.GetStrProperty(msgValue, "hotPlug")
        if ret:
            fullStatus.hotPlug = int(strValue)
            parse_ret += 1
        
        return True if parse_ret else False